﻿using Cofe.Core.Property;
using Cofe.Core.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cofe.Core.Filter
{
    [EntryFilter("name")]
    public class FileNameEntryFilter : EntryFilterBase
    {
        public FileNameEntryFilter(string name, string id = "name")
            : base(name, id)
        {
            SupportedMatchType = MatchType.MatchThisEntry;
        }

        public override MatchType matches(IPropertyHost entry,
            params IOptionFilter[] options)
        {
            string name = Value;
            string entryName = entry.Behaviors.GetProperty(CofeProperties.Name).ValueAsString;

            bool match = StringUtils.MatchFileMask(
                name.IndexOf('.') != -1 ?
                entryName :
                PathFE.RemoveExtension(entryName)
                , name);

            return match ? MatchType.MatchThisEntry : MatchType.None;


        }

    }
}
